import { Middleware } from 'koa'

export function use(middleware: Middleware) {
  return function (target: object, key: string) {
    const originMiddlewares =
      Reflect.getMetadata('middlewares', target, key) || []
    originMiddlewares.push(middleware)
    Reflect.defineMetadata('middlewares', originMiddlewares, target, key)
  }
}
